﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing;

namespace WINBASE.Controls
{
    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)]
    [DefaultProperty("Items")]
    public partial class WLCTspTextBox : WLCToolStripControlHost
    {
        public new event EventHandler TextChanged;

        #region Constructor & Load
        
        public WLCTspTextBox() : base(CreateControlInstance())
        {
            this.AutoSize = false;
            this.Size = new Size(80, 21);
        }

        public WLCTspTextBox(IContainer container)
            : base(CreateControlInstance())
        {
            container.Add(this);
        }

        public WLCTspTextBox(string name) : this()
        {
            this.Name = name;
        }

        private void OnTextChanged(object sender, EventArgs e)
        {
            if (TextChanged != null)
            {
                TextChanged(this, e);
            }
        }

        public TextBox TextBoxControl
        {
            get { return Control as TextBox; }
        }

        protected override void OnSubscribeControlEvents(Control control)
        {
            base.OnSubscribeControlEvents(control);
            TextBox tb = control as TextBox;

            if (tb != null)
            {
                tb.TextChanged += new EventHandler(OnTextChanged);
            }
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {
            base.OnUnsubscribeControlEvents(control);
            TextBox tb = control as TextBox;

            if (tb != null)
            {
                tb.TextChanged -= OnTextChanged;
            }
        }

        #endregion

        #region Method

        private static Control CreateControlInstance()
        {
            WLCTextBox txt = new WLCTextBox();
            txt.AutoSize = false;
            txt.Size = new Size(70, 20);
            return txt;
        }

        #endregion
    }
}
